const app = getApp();
var config = app.globalData.config;
const http = require('../../utils/http.js');

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		status: '',
    chooseid: 1,
    dataList:[],
    num:0
	},
	choose(e) {
		this.setData({
			chooseid: e.currentTarget.dataset.id
    });
    this.teacherApproval();
	},
	todetail(e) {
    let status = this.data.status;
    let id = e.currentTarget.dataset.id;
		if (e.currentTarget.dataset.approval == 'Pending') {
			wx.navigateTo({
				url: './detail?status=' + status+'&id='+id,
			})
		}
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		this.setData({
			status: options.status
    });
    this.teacherApproval();
  },
  teacherApproval() {
    var that = this;
    var leavetype = 0;
    if(that.data.status=="Supplementary"){
      leavetype = 2;
    }else{
      leavetype = 1;
    }
		http.httpPost(config.teacherApproval, {
			leavetype: leavetype,
			status: that.data.chooseid
		}, function(e) {
			if (e.code == 1) {
				console.log(e);
				that.setData({
					'dataList': e.data.list,
					'num': e.data.num
				});
			} else {

			}

		});
	},
	back() {
		wx.navigateBack({
			delta: 1,
		})
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {
		if (!app.login()) {
			return;
		}
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})
